import TodoItem from './TodoItem'

const TodoMain = ({ list, type }) => {
  let todoList = []
  if (type === 'All') {
    todoList = list
  } else if (type === 'Active') {
    todoList = list.filter((item) => item.done === false)
  } else {
    todoList = list.filter((item) => item.done === true)
  }
  return (
    <section className="main">
      <input id="toggle-all" className="toggle-all" type="checkbox" />
      <label htmlFor="toggle-all">Mark all as complete</label>
      <ul className="todo-list">
        {todoList.map((item) => {
          return <TodoItem key={item.id} item={item}></TodoItem>
        })}
      </ul>
    </section>
  )
}

export default TodoMain
